package teste;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

import bean.OSBean;
import conexao.Conexao;
import dao.OSDao;

public class mediaTempo {

	public static void main(String[] args) throws SQLException, ParseException {
		
		Connection conn = new Conexao().getConexao();
		List<OSBean> os = new OSDao().getListaOsData(conn);
		
		Timestamp datainicial;
		Timestamp datafinal;
		
		int dias = 0;
		int horas = 0;
	//	int minutos;
		
		
		for(int i=0; i < os.size(); i++){
			datainicial = os.get(i).getDataEntrada();
			datafinal = os.get(i).getDataFinalizado();
			
			Calendar inicio = new GregorianCalendar();
			inicio.setTimeInMillis(datainicial.getTime());
			Calendar fim = new GregorianCalendar();
			fim.setTimeInMillis(datafinal.getTime());
			dias +=  fim.get(Calendar.DAY_OF_YEAR) - inicio.get(Calendar.DAY_OF_YEAR);
			horas += fim.get(Calendar.HOUR_OF_DAY) - inicio.get(Calendar.HOUR_OF_DAY);
			
			
			//System.out.println(fim.get);
			
//			int mes = inicio.get(Calendar.MONTH) + 1;
//			int ano = inicio.get(Calendar.YEAR);
//			
//			int h = inicio.get(Calendar.HOUR_OF_DAY);
//			int m = inicio.get(Calendar.MINUTE);
//			
//			SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
			
			
		
			
			
			
		}
		
		int mediaH = horas / os.size();
		int mediaD = dias / os.size();
		
		System.out.println(mediaD +" e "+mediaH);

	}

}
